﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace Code4WP7SDK
{
    public class HtmlHelper
    {
        /// <summary>
        /// 移除HTML标签
        /// </summary>
        /// <param name="HTMLStr">HTMLStr</param>
        public static string ParseTags(string HTMLStr)
        {
            if (!string.IsNullOrEmpty(HTMLStr))
            {
                return System.Text.RegularExpressions.Regex.Replace(HTMLStr, "<[^>]*>", "");
            }
            return "";
        }
        /// <summary>
        /// 截取指定长度的中英文字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetStr(string str, int length)
        {
            string temp = str;
            if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= length)
            {
                return temp;
            }
            for (int i = temp.Length; i >= 0; i--)
            {
                temp = temp.Substring(0, i);
                if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= length - 3)
                {
                    return temp + ">>>";
                }
            }
            return ">>>";
        }
    }
}
